﻿using Microsoft.EntityFrameworkCore.Metadata;
using Service.Auth.Api.Application.Query;

namespace Service.Auth.Api.Host
{
    public class AuthHostService(
        ILogger<AuthHostService> logger,
        IServiceProvider serviceProvider) : IHostedService
    {
        public async Task StartAsync(CancellationToken cancellationToken)
        {
            await using (var scope = serviceProvider.CreateAsyncScope())
            {
                var query = scope.ServiceProvider.GetRequiredService<RolePemissionsQueryService>();
                logger.LogInformation("AuthHostService：Load cache ......");
                var list = await query.QueryRolePemissionItemCache();
                logger.LogInformation("AuthHostService ：totalCount：{Count}", list.Count);
                await Task.CompletedTask;
            }
        }

        public async Task StopAsync(CancellationToken cancellationToken)
        {
            logger.LogInformation("AuthHostService：StopAsync");
            await Task.CompletedTask;
        }
    }
}